package test.iceiceice.com.apptest;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.OnClick;
import test.iceiceice.com.apptest.core.ObservableUser;
import test.iceiceice.com.apptest.core.TestAdapter;
import test.iceiceice.com.apptest.core.User;
import test.iceiceice.com.apptest.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {
//    @Bind(R.id.tv)
//    TextView tv;
//    @Bind(R.id.btn)
//    Button btn;

    private ActivityMainBinding binding;
    private User user;
    private ObservableUser observableUser;
    private TestAdapter testAdapter;
    int num;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
        binding = DataBindingUtil.setContentView(
                this, R.layout.activity_main);
        user = new User("aaaaa", "bbbbb");

        user.setSex(false);
        binding.setUser(user);
        binding.setFirstName("哥哥");
        binding.setLastName("弟弟");
        binding.setName("伊利亚");
        ButterKnife.bind(this);

        observableUser = new ObservableUser("孙策", "伯符");
        binding.setObservableUser(observableUser);

        binding.recyclerView.setHasFixedSize(true);
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(this) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });

        ArrayList<ObservableUser> users = new ArrayList<>();
        users.add(new ObservableUser("小", "黄"));
        users.add(new ObservableUser("小", "蓝"));
        users.add(new ObservableUser("小", "蓝1"));
        users.add(new ObservableUser("小", "蓝2"));
        users.add(new ObservableUser("小", "蓝3"));
        users.add(new ObservableUser("小", "蓝4"));
        testAdapter = new TestAdapter(users, MainActivity.this);
        binding.recyclerView.setAdapter(testAdapter);
    }

    @OnClick(R.id.btn)
    public void onViewClicked() {
//        TestHttpNet.post(this, NetUrl.TOKEN, null, new TestCallBack() {
//            @Override
//            public void onGetToken(String response) {
//                super.onGetToken(response);
//                tv.setText("" + response);
//            }
//        });

        Log.d("bb", "onViewClicked: ");

        user.setFirstName("拉");
        user.setLastName("姆");
        user.setSex(true);

        binding.setUser(user);
        binding.setUrl(getResources().getString(R.string.test_img));
        binding.setFirstName("姐姐");
        binding.setLastName("妹妹");
        ArrayList<ObservableUser> users = new ArrayList<>();
        users.add(new ObservableUser("小" + num, "红111"));
        users.add(new ObservableUser("小" + num++, "青111"));


        testAdapter.getData().get(0).setFirstName("11111");
        testAdapter.getData().get(0).setLastName("22222");
        testAdapter.getData().get(1).setFirstName("aaaaaaaa");
        testAdapter.getData().get(1).setLastName("bbbbbbb");


        testAdapter.getData().addAll(users);
        testAdapter.notifyDataSetChanged();

        Log.d("bb", "onViewClicked: " + testAdapter.getData().size());

        for (int i = 0; i < testAdapter.getData().size(); i++) {
            Log.d("bb", "onViewClicked: " + testAdapter.getData().get(i).getFirstName() + testAdapter.getData().get(i).getLastName());
        }

        observableUser.setFirstName("赵云");
        observableUser.setLastName("子龙");

    }
}
